# 定义一个类，来封装方法和流程
import requests
from common.DBUtil import DBUtil
from config import BASE_URL

class LoginApi(object):

    def __init__(self):
        self.login_img_get_url = BASE_URL + "/api/captchaImage"
        self.login_post_url = BASE_URL + "/api/login"

    # 获取图片验证码
    def get_img_code(self):
        response = requests.get(self.login_img_get_url)
        return response

    # 登录
    def post_login(self, username, password, code, uuid):
        login_data = {"username": username,
                      "password": password,
                      "code": code,
                      "uuid": uuid}

        resp = requests.post(self.login_post_url, json=login_data)
        return resp

    def update_course(self,id):
        sql = f"update tb_course set name = '大风起兮' where id = {id};"
        DBUtil.uid_db(sql)
        sql1 = f"select name,id from tb_course where id = {id};"
        print(DBUtil.get_one(sql1))
        cou_name = DBUtil.get_one(sql1)[0][0]
        return cou_name

if __name__ == "__main__":
    logindata = LoginApi()
    print(logindata.update_course(23891))




